<form class="form-inline">
    <div class="form-group">
        <label class="sr-only" for="exampleInputPassword3"></label>
        <input type="text" id="course_name" name="courseName" value="{{$name}}" class="form-control" id="exampleInputPassword3" placeholder="课程名称">
    </div>
    <button type="button"  data-id="{{$class_id}}" data-page="1" data-name="" onclick="courseLiveList(this);"  class="btn btn-default">查询</button>
</form>
<table class="table table-striped">
    <thead>
    <tr>

        <th>课程名称</th>
        <th>直播时间</th>
        <th>直播状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    @foreach($courses as $course)
        <tr>
            <td scope="row">{{$course->title}}</td>
            <td scope="row">{{date('Y-m-d H:i:s',strtotime($course->live_start_time))}}</td>
            @if(strtotime($course->live_start_time) > time())
            <td>待直播</td>
            @elseif(strtotime($course->live_start_time) < time() && strtotime($course->live_end_time) > time())
            <td>直播中</td>
            @else
            <td>已结束</td>
            @endif
            <td><button class="btn btn-primary" onclick="cancelLive(this);" data-id="{{$course->id}}" data-name="{{$course->title}}">取消直播</button></td>
        </tr>
    @endforeach
    </tbody>
</table>
<nav aria-label="Page navigation">
    <ul class="pagination">
        <li>
            <a href="#" aria-label="Previous">
                <span aria-hidden="true" data-name="{{$name}}" data-id="{{$class_id}}" data-page="1"  onclick="courseLiveList(this);">首页</span>
            </a>
        </li>
        @if($courses->currentPage() > 1)
            <li>
                <span aria-hidden="true" data-id="{{$class_id}}" data-page="{{$courses->currentPage() -1}}" data-name="{{$name}}" onclick="courseLiveList(this);">上一页</span>
            </li>
        @endif
        @if($courses->hasMorePages())
            <li>
                <span aria-hidden="true" data-id="{{$class_id}}" data-page="{{$courses->currentPage() + 1}}" data-name="{{$name}}" onclick="courseLiveList(this);">下一页</span>
            </li>
        @endif
        <li>
            <span aria-hidden="true" data-name="{{$name}}" data-id="{{$class_id}}" data-page="{{$courses->lastPage()}}" onclick="courseLiveList(this);">尾页</span>
        </li>
    </ul>
</nav>
<style type="text/css">
    li > span{
        cursor:pointer;
    }
    tr > td > a{
        cursor:pointer;
    }
</style>
<script type="text/javascript">
    function cancelLive(obj){

        var id = $(obj).attr('data-id');
        var _token = '{{csrf_token()}}';
        var page = $(obj).attr('data-page');
        var data = {id:id,_token:_token,page:page};
        var page = $('');
        $.ajax({
            url:"/course/live/setting",
            data:data,
            type:'POST',
            dataType:'json',
            success:function(res){
                if(res.code == 0){
                    $(obj).parent().parent().remove();
                    swal(res.message);
                }
            }
        });
    }
</script>